const nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport({
    service: 'qq',
    auth: {
        user: '2824642101@qq.com',
        pass: 'oakqrzrrroukdcce' //授权码,通过QQ获取  

    }
});

async function sendEmail(to, Vcode) {
    const mailOptions = {
        from: '2824642101@qq.com', // 发送者  
        to, // 接受者,可以同时发送多个,以逗号隔开  
        subject: '面试指南平台新用户注册', // 标题  
        html: `<h2>尊敬的用户您好，欢迎注册面试指南平台:</h2><br/><h3>您的验证码是：${Vcode}</h3>`
    }
    const res = await transporter.sendMail(mailOptions);
    if (res.response.slice(4, 6) !== 'OK') {
        return false
    }
    return true
}

let num = ''
function setNum() {
    num = ''
    for (let i = 0; i < 6; i++) {
        num += Math.floor(Math.random() * 10);
    }
    return num
}
function getNum() {
    return num
}
module.exports = {
    sendEmail,
    setNum,
    getNum
}